# SPDX-License-Identifier: MIT

set(_FRODOKEM_OBJS "")

if(OQS_ENABLE_KEM_frodokem_640_aes)
    set(SRCS kem_frodokem640aes.c external/frodo640aes.c)
endif()
if(OQS_ENABLE_KEM_frodokem_640_shake)
    set(SRCS ${SRCS} kem_frodokem640shake.c external/frodo640shake.c)
endif()

if(OQS_ENABLE_KEM_frodokem_976_aes)
    set(SRCS ${SRCS} kem_frodokem976aes.c external/frodo976aes.c)
endif()
if(OQS_ENABLE_KEM_frodokem_976_shake)
    set(SRCS ${SRCS} kem_frodokem976shake.c external/frodo976shake.c)
endif()

if(OQS_ENABLE_KEM_frodokem_1344_aes)
    set(SRCS ${SRCS} kem_frodokem1344aes.c external/frodo1344aes.c)
endif()
if(OQS_ENABLE_KEM_frodokem_1344_shake)
    set(SRCS ${SRCS} kem_frodokem1344shake.c external/frodo1344shake.c)
endif()

add_library(frodokem OBJECT ${SRCS})
set(_FRODOKEM_OBJS ${_FRODOKEM_OBJS} $<TARGET_OBJECTS:frodokem>)

set(SRCS_AVX2 "")
if(OQS_DIST_X86_64_BUILD OR OQS_USE_AVX2_INSTRUCTIONS)
    if(OQS_ENABLE_KEM_frodokem_640_aes)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo640aes_avx2.c)
    endif()
    if(OQS_ENABLE_KEM_frodokem_976_aes)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo976aes_avx2.c)
    endif()
    if(OQS_ENABLE_KEM_frodokem_1344_aes)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo1344aes_avx2.c)
    endif()

    if(OQS_ENABLE_KEM_frodokem_640_shake)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo640shake_avx2.c)
    endif()
    if(OQS_ENABLE_KEM_frodokem_976_shake)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo976shake_avx2.c)
    endif()
    if(OQS_ENABLE_KEM_frodokem_1344_shake)
        set(SRCS_AVX2 ${SRCS_AVX2} external/frodo1344shake_avx2.c)
    endif()

    add_library(frodokem_avx2 OBJECT ${SRCS_AVX2})
    target_compile_options(frodokem_avx2 PRIVATE -mavx2)
    set(_FRODOKEM_OBJS ${_FRODOKEM_OBJS} $<TARGET_OBJECTS:frodokem_avx2>)
endif()

set(FRODOKEM_OBJS ${_FRODOKEM_OBJS} PARENT_SCOPE)
